#include <iostream>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/RollingFileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>
using namespace std;
using namespace log4cpp;
void test()
{
    // 设置日志布局
    PatternLayout *p1 = new PatternLayout();
    p1->setConversionPattern("%d %c [%p] %m%n");
    PatternLayout *p2 = new PatternLayout();
    p2->setConversionPattern("%d %c [%p] %m%n");
    PatternLayout *p3 = new PatternLayout();
    p3->setConversionPattern("%d %c [%p] %m%n");
    // 创建输出器对象
    OstreamAppender *pos = new OstreamAppender("console", &cout);
    FileAppender *filepos = new FileAppender("file", "log4_three.log");
    RollingFileAppender *pos3 = new RollingFileAppender("rollingfile", "rollinglog3.log", 5 * 1024, 3);
    pos->setLayout(p1);
    filepos->setLayout(p2);
    pos3->setLayout(p3);
    // 创建日志记录器
    Category &root = Category::getRoot();
    root.setPriority(Priority::ERROR);

    // 设置输出器
    root.addAppender(pos);
    root.addAppender(filepos);
    root.addAppender(pos3);

    root.emerg("this is emerge message");
    root.fatal("this is fatal message");
    root.alert("this is alert message");
    root.crit("this is crit message");
    root.error("this is error message");
    root.warn("this is warn message");
    root.notice("this is notice message");
    root.info("this is info message");
}
int main()
{
    test();
    return 0;
}